{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c1c09377",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd6ecb08",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取当前坐标轴上的图例句柄（handles）和标签（labels）\n",
    "handles, labels = plt.gca().get_legend_handles_labels()\n",
    "\n",
    "# 定义新的顺序（列表索引）\n",
    "# 原本的顺序是：Trendline(0), TLDP(1), LPPM(2), DPLPA(3), UPDP-LPP(4)\n",
    "# 期望的顺序是：Trendline(0), TLDP(1), UPDP-LPP(4), LPPM(2), DPLPA(3)\n",
    "new_order = [0, 1, 4, 2, 3]  \n",
    "\n",
    "# 按照新的顺序重新排列句柄和标签\n",
    "handles = [handles[i] for i in new_order]\n",
    "labels = [labels[i] for i in new_order]\n",
    "\n",
    "# 使用重新排列后的句柄和标签来生成图例\n",
    "plt.legend(handles, labels)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
